<?php

/**
 * This is the model class for table "pccongtackhac".
 *
 * The followings are the available columns in table 'pccongtackhac':
 * @property integer $STT
 * @property string $magv
 * @property string $maCTK
 * @property string $ghichu
 * @property integer $nambd
 * @property integer $namkt
 */
class Pccongtackhac extends CActiveRecord
{
	public $giangvien_tengv_search;
	public $congtackhac_tenCTK_search;
	public $namhoc;
	public $SLNhap;
	public $nhoc;
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'pccongtackhac';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('STT, magv', 'required'),
			array('STT, nambd, namkt', 'numerical', 'integerOnly'=>true),
			array('magv', 'length', 'max'=>11),
			array('maCTK', 'length', 'max'=>128),
			array('ghichu', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('STT, magv, maCTK, ghichu, nambd, namkt, giangvien.tengv, giangvien_tengv_search, congtackhac.tenCTK, congtackhac_tenCTK_search', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'giangvien'=>array( self::BELONGS_TO, 'Giangvien', 'magv' ),
			'congtackhac'=>array( self::BELONGS_TO, 'Congtackhac', 'maCTK' ),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'STT' => 'Stt',
			'magv' => 'Giảng viên',
			'maCTK' => 'Công tác khác',
			'ghichu' => 'Ghi chú',
			'nambd' => 'Năm bắt đầu',
			'namkt' => 'Năm kết thúc',
			'namhoc' => 'Năm học',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('STT',$this->STT);
		$criteria->compare('magv',$this->magv,true);
		$criteria->compare('maCTK',$this->maCTK,true);
		$criteria->compare('ghichu',$this->ghichu,true);
		$criteria->compare('nambd',$this->nambd);
		$criteria->compare('namkt',$this->namkt);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
			'sort'=>array(
				'defaultOrder'=>'magv ASC',
			),
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Pccongtackhac the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
